<%@ Register TagPrefix="freak" Namespace="freak" Assembly = "fricchettone"%>
<%@ Page Language="C#" Description="Homepage" debug="true" trace="false" Culture="it-IT" EnableViewState="false"%>
<%@ Import Namespace="dammelau"%>

<%@ Import Namespace="System.Net"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Text"%>


<%
sqlUtil sqlu = new    sqlUtil();
usrUtil usru = new    usrUtil(Page);
api apiUtil = new api();

if (apiUtil.GetParameterValue(Page, "language") != null)
{
    if (apiUtil.GetParameterValue(Page, "language") != "")
    {
        apiUtil.language = apiUtil.GetParameterValue(Page, "language").ToLower();
    }
}
    
if (Request.QueryString.Get("command") == null)
{
    return;
}
else
{
    string comm = Request.QueryString.Get("command").ToLower();
    string AJAX_return = "";
    
    switch(comm)
    {
        case "userexistence":
            if( apiUtil.validateHostKey(Page) )
                AJAX_return = apiUtil.UserExistence(Page);
            break;

        case "gimmecountries":

            AJAX_return = sqlu.executeText(
                    "exec freak_gimmeCountries"
                    );
            break;
                
        case "gimmeregions":
            
            if (Request.QueryString.Get("country") != null)
                {
                string code = Request.QueryString.Get("country");
                AJAX_return = sqlu.executeText(
                        "exec freak_gimmeRegions @isocountry='" + Request.QueryString.Get("country").Replace("'", "''") + "'"
                        );
                }
                break;
            
        case "gimmecities":

            if ((Request.QueryString.Get("country") != null) && (Request.QueryString.Get("region") != null))
            {
                string code = Request.QueryString.Get("country");
                AJAX_return = sqlu.executeText(
                        "exec freak_gimmeCities @isocountry='" + Request.QueryString.Get("country").Replace("'", "''") + "'"
                            + ", @fips_region='" + Request.QueryString.Get("region").Replace("'", "''") + "'"
                        );
            }
            break;
    }

    Response.ContentType = "text/xml";
    Response.Write(AJAX_return);       
}
    
%>
